package com.datn.activity;

import java.util.ArrayList;
import java.util.List;

import com.datn.DataAccess.DBAdapter;
import com.datn.utils.AlertCustom;
import com.datn.utils.GPSCustom;
import com.datn.utils.HelloItemizedOverlay;
import com.datn.utils.places.Json_Place;
import com.datn.utils.places.Place;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.ListActivity;
import android.app.AlertDialog.Builder;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.GridView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.LinearLayout.LayoutParams;
import android.widget.SimpleCursorAdapter;

public class NearLocationActivity extends MapActivity  {
    /** Called when the activity is first created. */
	/*
	  //-----Test MapView have ZoomControl----- 
	 MapView mapView;
	MapController mc;
	GeoPoint p;*/
	
	/*
	 //Test Database
	 private DBAdapter mDB;
	private Cursor mCursor;
	
	private void getData(){
    	mCursor = mDB.getAllUsers();
    	startManagingCursor(mCursor);
    	mCursor.moveToFirst();
    	
    	StringBuilder sb=new StringBuilder();
    	while (mCursor.moveToNext()){
    		sb.append("Element:"+mCursor.getString(mCursor.getColumnIndexOrThrow(DBAdapter.KEY_NAME))+"\n");
    	}
    	
    	AlertDialog.Builder alert=new Builder(this);
    	alert.setMessage(sb.toString());
    	alert.setTitle("Title");
    	alert.show();
    }*/
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
       /*
        //Test GridView and ListView
        setContentView(R.layout.testlistview);
       
       ListView lsView= (ListView) findViewById(R.id.lsView);
       ArrayList<String> stList=new ArrayList<String>();
       stList.add("Trung");
       stList.add("VN");
       CustomListAdapter adapterList=new CustomListAdapter(this, R.layout.item, stList);
       lsView.setAdapter(adapterList);
       stList.add("VNVNVNVN");
       
       GridView gridview = (GridView) findViewById(R.id.gridview);
       
       ArrayList<String> stList2=new ArrayList<String>();
       for (int i = 0; i < 12; i++) {
		stList2.add("Trung "+i);
	}
       CustomListAdapter adapterList2=new CustomListAdapter(this, R.layout.item, stList2);
       
       gridview.setAdapter(adapterList2);
       */
      
        /*
         //Test Database
         Button btRegister=(Button)findViewById(R.id.btLogin);
        mDB = new DBAdapter(this);
        mDB.open();
        mDB.createUser("Do Minh Thong n");
        btRegister.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				getData();
			}
		});
        //getData();
        */
        
        
       
        
        
        /*
        //MapView OVERLAY
        MapView mapView = (MapView) findViewById(R.id.mapview);
        mapView.setBuiltInZoomControls(true);
        
        List<Overlay> mapOverlays = mapView.getOverlays();
        Drawable drawable = this.getResources().getDrawable(R.drawable.androidmarker);
        HelloItemizedOverlay itemizedoverlay = new HelloItemizedOverlay(drawable, this);
        
        
        GeoPoint point = new GeoPoint(19240000,-99120000);
        OverlayItem overlayitem = new OverlayItem(point, "Hola, Mundo!", "I'm in Mexico City!");
        
        itemizedoverlay.addOverlay(overlayitem);
        mapOverlays.add(itemizedoverlay);
        */
        
        
        
       /*
        //------Test GPS -----
        Button btRegister=(Button)findViewById(R.id.btRegister);
        Button btCancel=(Button)findViewById(R.id.btCancel);
        btRegister.setOnClickListener(this);
        */
     
       
        
        
        /* 
        //-----Test MapView have ZoomControl-----
        mapView = (MapView)findViewById(R.id.myMap);
        LinearLayout zoomLayout = (LinearLayout)findViewById(R.id.zoom);
        View zoomView = mapView.getZoomControls();
        zoomLayout.addView(zoomView, new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
        mapView.displayZoomControls(true);
        mapView.setSatellite(false);
        mapView.setStreetView(false);
        mapView.setTraffic(true);
        
        String coordinates[] = {"21.036074","105.833636"};
        double latiTude = Double.parseDouble(coordinates[0]);
        double longiTude = Double.parseDouble(coordinates[1]);
        p = new GeoPoint((int)(latiTude * 1E6) ,(int)(longiTude * 1E6));
        
        mc = mapView.getController();
        mc.animateTo(p);
        mc.setZoom(17);
        mapView.invalidate();*/
        
        
        
    }

	/* 
	 //-------Test GPS-----
	 @Override
	public void onClick(View v) {
		try {
			GeoPoint coor=new GPSCustom(this).getCurrentLocation();
			AlertCustom.showAlert(this, "Current Location", "Lat:"+ coor.getLatitudeE6() + " Lon: "+ coor.getLongitudeE6());
			
			StringBuilder sb=new StringBuilder();
			
			Json_Place place=new Json_Place(this);
			List<Place> listPlace = place.getListAdressByType("atm", new GeoPoint(coor.getLatitudeE6(), coor.getLongitudeE6()));
			
			sb.append("Size:"+listPlace.size()+"\n");
			
			for (int i = 0; i < listPlace.size(); i++) {
				sb.append("Name:"+listPlace.get(i).getName()+" Addr:"+listPlace.get(i).getAddressLine()+" Lat:"+listPlace.get(i).getLatitude()+"\n");
			}
			AlertCustom.showAlert(this, "Result", sb.toString());
			
		} catch (Exception e) {
			// TODO: handle exception
			AlertCustom.showAlert(this,"ERROR", e.getMessage() );
		}
			
		
		
		
		
	}*/

	@Override
	protected boolean isRouteDisplayed() {
		// TODO Auto-generated method stub
		return false;
	}
}